﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace TwoWheels
{
    public partial class ShowImage : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            const string cnStr = @"Data Source=DUO-P8600;Initial Catalog=TwoWheels;Integrated Security=True";
            System.Data.SqlClient.SqlDataReader Reader = null;
            string ImageIdentity = Request.QueryString["id"].ToString();
            string FromWhere = Request.QueryString["source"].ToString();
            SqlConnection sqlConnection = new SqlConnection(cnStr);
            sqlConnection.Open();
            SqlCommand sqlCommand = null;
            string temp = "Select Zdjecie from " + FromWhere + " where " + FromWhere + "ID =" + ImageIdentity;
            if (FromWhere.CompareTo("Kategoria") == 0) sqlCommand = new SqlCommand("Select Zdjecie from " + FromWhere + " where " + FromWhere + "ID =" + ImageIdentity, sqlConnection);
            else sqlCommand = new SqlCommand("Select Zdjecie from " + FromWhere + " where NazwaProduktu ='" + ImageIdentity + "'", sqlConnection);
            Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
            Reader.Read();
            byte[] byteArray = (byte[])Reader["Zdjecie"];
            //Response.ContentType = Reader["KategoriaID"].ToString();
            Response.BinaryWrite(byteArray);
        }
    }
}